package com.moon.game.command.guest.lair;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.ErrorCode;
import com.moon.game.exception.GException;
import com.moon.game.manager.AnimalChildMG;
import com.moon.game.manager.AnimalMG;
import com.moon.game.resource.model.Animal;
import com.moon.game.resource.model.AnimalChild;
import com.moon.game.vos.ErrorMsg;

/**
 * @description 查看珍兽孵化资源
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-2 上午11:42:11
 */
public class ViewTheAnimalCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
		case STATU_INIT:
			doInit(req);
			break;
		case STATU_CHECK:
			doCheckSelf(req);
			break;
		case STATU_RETURN:
			doResponse(req);
			break;
		default:
			break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		Integer animalId = Integer.parseInt(ps[0]);
		if (animalId == null) {
			doResponsePsError(req);
			return;
		}
		
		Animal animal = AnimalMG.instance.getAnimal(animalId);
		if (animal == null) {
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_RESOURCE, "珍兽资源库中找不到指定珍兽！"));
			return;
		}
		
		AnimalChild child = AnimalChildMG.instance.getAnimalChild(animal.getChildId());
		if (child == null) {
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_RESOURCE, "珍兽孵化资源库中找不到指定孵化兽！"));
			return;
		}
		
		req.setVO("animal_child_id", animal.getChildId());
		response(req, req.getClientResponse());
	}

}
